<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>教务员-录入教师信息</title>
    <link rel="stylesheet" href="${ctx}/static/layui/css/layui.css">
    <link rel="stylesheet" href="${ctx}/static/css/index.css">
    <style>
        .body-from {
            margin-top: 20px;
        }

        .mylabel {
            color: #000000;
            font-weight: bold;
            font-size: 18px;
        }

        .layui-form-item {
            padding-top: 14px;
        }
    </style>
</head>
<body>
<!-- 主体 -->
<div class="body-head"><span>教师信息管理&nbsp;>&nbsp;录入教师信息</span></div>
<form class="body-from layui-form" id="submit_teacher">
    <div class="layui-form-item">
        <label class="layui-form-label mylabel">工号</label>
        <div class="layui-input-block">
            <input type="text" name="jobNo" id="jobNo" placeholder="请输入教师工号" class="layui-input" style="width: 600px;">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label mylabel">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="name" id="name" placeholder="请输入教师姓名" class="layui-input" style="width: 600px;">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label mylabel">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="男" title="男" checked="">
            <input type="radio" name="sex" value="女" title="女">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label mylabel">年龄</label>
            <div class="layui-input-block">
                <input type="text" name="age" placeholder="请输入教师年龄(选填)" class="layui-input"
                       style="width: 600px;">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label mylabel">所属系</label>
            <div class="layui-input-block">
                <input type="text" name="department" readonly="readonly" value="计算机系" class="layui-input layui-disabled"
                       style="width: 600px;">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label mylabel">电话</label>
            <div class="layui-input-block">
                <input type="text" name="phone" id="phone" placeholder="请输入教师的联系电话" class="layui-input"
                       style="width: 600px;">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" id="btn" class="layui-btn">提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script src="${ctx}/static/js/jquery.min.js"></script>
<script src="${ctx}/static/layui/layui.js"></script>
<script src="${ctx}/static/js/index.js"></script>
<script>
    layui.use(['jquery', 'layer'], function () {
        let $ = layui.$;
        let layer = layui.layer;

        $("#btn").on("click", function () {
            if ($("#jobNo").val() == "") {
                layer.msg("工号不允许为空");
                return;
            } else if (!/^\d{4}$/.test($("#jobNo").val())) {
                layer.msg("工号格式不正确");
                return;
            } else if ($("#name").val() == "") {
                layer.msg("姓名不允许为空");
                return;
            } else if (!/^[\u4e00-\u9fa5]{2,6}$/.test($("#name").val())) {
                layer.msg("只能输入中文名字");
                return;
            } else if ($("#phone").val() == "") {
                layer.msg("电话号码不允许为空");
                return;
            } else if (!/^1[3|4|5|7|8][0-9]{9}$/.test($("#phone").val())) {
                layer.msg("电话号码格式不正确");
                return;
            } else {
                layer.confirm("确定要提交吗？", {btn: ['确定', '取消'], title: "提示"}, function () {
                    $.ajax({
                        type: "post",
                        url: "${ctx}/academic/addTeacher.action",
                        data: $("#submit_teacher").serialize(),
                        dataType: "json",
                        contentType: "application/x-www-form-urlencoded",
                        success: function (data) {
                            //console.log(data);
                            if (data.flag) {
                                layer.msg("添加成功");
                            } else {
                                layer.msg("添加失败");
                            }
                        },
                        error: function () {
                            layer.msg("请求失败");
                        }
                    });
                    layer.closeAll('dialog');
                });
            }
        });


    });
</script>
</body>
</html>
